package kmu.lwl.controller;

import kmu.lwl.entiy.Connection;
import kmu.lwl.entiy.Login;
import kmu.lwl.imp.CourseDao;
import kmu.lwl.imp.impl.CourseDaoimpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.util.List;
import java.util.Map;

public class ChoseCourseController extends ActionSupport {
    private Connection connection;

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public String allCourse() throws Exception{
        CourseDao courseDao = new CourseDaoimpl();
        List allCourse = courseDao.getAllCourse();
        Map request = (Map) ActionContext.getContext().get("request");
        request.put("allCourse",allCourse);
        return SUCCESS;
    }
    public String chose() throws Exception{
        Map session = (Map) ActionContext.getContext().getSession();
        Login user = (Login) session.get("user");
        connection.setStudentId(user.getLoginName());
        CourseDao courseDao = new CourseDaoimpl();
        Boolean b = courseDao.courseSelection(connection);
        if(b==true) {
            return SUCCESS;
        }else {
            return "error";
        }
    }
}
